package makabakaquestionnaire.zutsoftware.controller;

import makabakaquestionnaire.zutsoftware.annotation.Log;
import makabakaquestionnaire.zutsoftware.entity.ProjectTemplateCategory;
import makabakaquestionnaire.zutsoftware.entity.page.TableDataInfo;
import makabakaquestionnaire.zutsoftware.enums.BusinessType;
import makabakaquestionnaire.zutsoftware.service.IProjectTemplateCategoryService;
import makabakaquestionnaire.zutsoftware.system.common.AjaxResult;
import makabakaquestionnaire.zutsoftware.system.common.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 模板目录Controller
 *
 * @author wjf
 * @date 2022-04-03
 */
@RestController
@RequestMapping("/system/category")
public class ProjectTemplateCategoryController extends BaseController {
    @Autowired
    private IProjectTemplateCategoryService projectTemplateCategoryService;

    /**
     * 查询模板目录列表
     */
    @PreAuthorize("@ss.hasPermi('system:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProjectTemplateCategory projectTemplateCategory) {
        startPage();
        List<ProjectTemplateCategory> list = projectTemplateCategoryService.selectProjectTemplateCategoryList(projectTemplateCategory);
        return getDataTable(list);
    }

    /**
     * 新增模板目录
     */
    @PreAuthorize("@ss.hasPermi('system:category:add')")
    @Log(title = "模板目录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectTemplateCategory projectTemplateCategory) {
        return toAjax(projectTemplateCategoryService.insertProjectTemplateCategory(projectTemplateCategory));
    }

    /**
     * 修改模板目录
     */
    @PreAuthorize("@ss.hasPermi('system:category:edit')")
    @Log(title = "模板目录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectTemplateCategory projectTemplateCategory) {
        return toAjax(projectTemplateCategoryService.updateProjectTemplateCategory(projectTemplateCategory));
    }

    /**
     * 删除模板目录
     */
    @PreAuthorize("@ss.hasPermi('system:category:remove')")
    @Log(title = "模板目录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(projectTemplateCategoryService.deleteProjectTemplateCategoryByIds(ids));
    }
}